package com.x.client.fragment

import android.support.v4.content.ContextCompat
import android.support.v7.widget.DividerItemDecoration
import android.support.v7.widget.LinearLayoutManager
import android.view.ViewGroup
import android.widget.ImageView
import com.alibaba.android.arouter.launcher.ARouter
import com.gg.baselibrary.BaseFragment
import com.gg.utils.StatusUtils
import com.jakewharton.rxbinding2.view.RxView
import com.x.client.R
import com.x.client.adapter.CarListAdapter
import com.x.client.utils.RouterClass
import kotlinx.android.synthetic.main.fragment_sale_car.*
import java.util.concurrent.TimeUnit

/**
 * Creator : GG
 * Date    : 2018/5/21
 * Mail    : gg.jin.yu@gmai.com
 * Explain :
 */
class SaleCarFragment : BaseFragment() {


    private val adapter: CarListAdapter  by lazy { CarListAdapter() }

    companion object {
        fun newInstance() = SaleCarFragment()
    }

    override fun getLayoutResId(): Int = R.layout.fragment_sale_car


    override fun initView() {
        super.initView()
        statusBar.layoutParams.apply {
            height = StatusUtils.getStatusBarHeight(context!!)
        }

        recyclerView.layoutManager = LinearLayoutManager(context)
        recyclerView.addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL).apply {
            setDrawable(ContextCompat.getDrawable(this@SaleCarFragment.context!!, R.drawable.divider_ll_grey_h)!!)
        })

        val imageView = layoutInflater.inflate(R.layout.item_image, recyclerView.parent as ViewGroup, false) as ImageView

        imageView.setImageResource(R.drawable.banner_sale_car)
        adapter.addHeaderView(imageView, 0)


        RxView.clicks(saleCar)
                .throttleFirst(1, TimeUnit.SECONDS)
                .compose(this.bindToLifecycle())
                .subscribe {
                    ARouter.getInstance().build(RouterClass.saleCar)
                            .navigation()
                }

    }

}